import { FC, useEffect, useState } from "react"
import { Provider } from "./context"
import { ITodo } from "./data"

const initData = [
  {
    value: 'xuexi',
    completed: false,
    id: 0
  }
]

const Cpr: FC = (props) => {

  const [data, setData] = useState<ITodo[]>(initData)

  const addTodo = (val: ITodo): void => {
    setData(pre => {
      return [...pre, val]
    })
  }
  const toggleTodo = () => {

  }
  const removeTodo = () => {

  }
  return (<Provider value={
    {
      todoList: data,
      addTodo,
      toggleTodo,
      removeTodo,
    }
  }>{props.children}</Provider>)
}

export default Cpr